/**
 * Created by liuzengrong on 2019/8/16.
 */
import React from 'react';
import { connect } from 'dva';
import StandardModule from '@/components/hyperspace/modules/StandardModule';
import RoleRights from './components/RoleRights';


let roleRights: any = {};

/**
 * 自定义模块
 */
// @ts-ignore
const LocalModule: React.FC = ({ role, dispatch }) => (
    <div>
      <StandardModule
        data={role.data}
        dictionary={[
        ]}
        config={{
          common: {
            formItemOptions: {
              roleName: {
                rules: [{ required: true, message: '角色名称不能为空！' }],
              },
              description: {
                rules: [{ required: true, message: '角色名称不能为空！' }],
              },
              status: {
                rules: [{ required: true, message: '状态不能为空！' }],
              },
            },
          },
          search: {
            fields: ['roleName'], // 查询条件
          },
          list: {
            url: '/api/role/query',
            fields: [
              'id',
              'roleName',
              'description',
              'status',
              'creatTime',

            ], // 列表字段
            format: {
              username: {
                render: (value: any) => `格式化 - ${value}`,
              },
            },
            extensions: {
              operations: [
                (record: any) => (
                  <span>
                    <a
                      onClick={() => {
                        if (roleRights) roleRights.handleOpen();
                      }}
                    >
                      权限配置
                    </a>
                </span>
                ),
              ],
            },
          },
          add: {
            url: '/api/role/create',
            // width: 680, // 非必填，默认680px
            // title: '新建表单', // 非必填，默认`新建`
            fields: [
              'roleName',
              'description',
              'status',
            ], // 新增表单字段
          },
          update: {
            url: '/api/role/update',
            // width: 680, // 非必填，默认680px
            // title: '新建表单', // 非必填，默认`新建`
            fields: [
              'roleName',
              'description',
              'status'
            ], // 修改表单字段
            primaryKeys: ['id'], // 主键字段列表
          },
          delete: {
            url: '/api/role/remove',
            batchDelete: false, // 是否开启批量删除
            fields: ['id'], // 删除依据字段
          },
        }}
        namespace="role"
        dispatch={dispatch}
      />

      {/* eslint-disable-next-line no-return-assign */}
      <RoleRights wrappedComponentRef={(inst: any) => (roleRights = inst)}
        {...roleRights}
        visible
      />
    </div>

);

// @ts-ignore
export default connect(({ role }) => ({
  role,
}))(LocalModule);
